package com.xbongbong.saas.enums.business;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.ScreenTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 节点日志信息枚举
 *
 * @author LiZhikang
 * @date 2023/1/10 16:14
 */
@Getter
public enum WorkOrderV2NodeLogInfoEnum {
    //    NODE_TYPE("nodeType", "enum.workOrderV2NodeLogInfo.attrName.nodeType", "nodeType", FieldTypeEnum.NODE_TYPE.getType(),
//            1, 0, 0, ShowTypeEnum.ALL.getCode(), 3, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 节点名称
     **/
    NODE_ID("nodeId", "enum.workOrderV2NodeLogInfo.attrName.nodeId", "nodeId", FieldTypeEnum.NODE_ID.getType(),
            1, 0, 0, ShowTypeEnum.ALL.getCode(), 1, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 停留时长
     */
    STAY_TIME("stayTime","enum.workOrderV2NodeLogInfo.attrName.stayTime", "stayTime", FieldTypeEnum.NUM.getType(),
            1, 0, 0, ShowTypeEnum.ALL.getCode(), 2, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 节点进入时间
     */
    START_TIME("startTime","enum.workOrderV2NodeLogInfo.attrName.startTime", "startTime", FieldTypeEnum.DATETIME.getType(),
            1, 0, 0, ShowTypeEnum.ALL.getCode(), 3, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 开始环节签到时间
     */
    START_SIGN_TIME("startSignTime","enum.workOrderV2NodeLogInfo.attrName.startSignTime", "startSignTime", FieldTypeEnum.DATETIME.getType(),
            1, 0, 0, ShowTypeEnum.ALL.getCode(), 4, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 完成环节签退时间
     */
    FINISH_SIGN_BACK_TIME("finishSignBackTime","enum.workOrderV2NodeLogInfo.attrName.finishSignBackTime", "finishSignBackTime", FieldTypeEnum.DATETIME.getType(),
            1, 0, 0, ShowTypeEnum.ALL.getCode(), 5, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 接受环节进入时间
     */
    ACCEPT_IN_TIME("acceptStartTime","enum.workOrderV2NodeLogInfo.attrName.acceptInTime", "acceptStartTime", FieldTypeEnum.DATETIME.getType(),
            1, 0, 0, ShowTypeEnum.ALL.getCode(), 6, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 开始环节进入时间
     */
    START_IN_TIME("startStartTime","enum.workOrderV2NodeLogInfo.attrName.startInTime", "startStartTime", FieldTypeEnum.DATETIME.getType(),
            1, 0, 0, ShowTypeEnum.ALL.getCode(), 7, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 完成环节进入时间
     */
    FINISH_IN_TIME("finishStartTime","enum.workOrderV2NodeLogInfo.attrName.finishInTime", "finishStartTime", FieldTypeEnum.DATETIME.getType(),
            1, 0, 0, ShowTypeEnum.ALL.getCode(), 8, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 指派操作人
     */
    ASSIGNED_USER("assignedUser","enum.workOrderV2NodeLogInfo.attrName.assignedUser", "assignedUser", FieldTypeEnum.USER.getType(),
            1, 0, 0, ShowTypeEnum.ALL.getCode(), 9, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 完成操作人
     */
    FINISH_FINISH_USER("finishFinishUser","enum.workOrderV2NodeLogInfo.attrName.finishFinishUser", "finishFinishUser", FieldTypeEnum.USER.getType(),
            1, 0, 0, ShowTypeEnum.ALL.getCode(), 10, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 回访操作人
     */
    VISIT_USER("visitUser","enum.workOrderV2NodeLogInfo.attrName.visitUser", "visitUser", FieldTypeEnum.USER.getType(),
            1, 0, 0, ShowTypeEnum.ALL.getCode(), 11, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 自由节点完成操作人
     */
    FREE_FINISH_USER("freeFinishUser","enum.workOrderV2NodeLogInfo.attrName.freeFinishUser", "freeFinishUser", FieldTypeEnum.USER.getType(),
            1, 0, 0, ShowTypeEnum.ALL.getCode(), 12, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 结算节点操作人
     */
    SETTLEMENT_USER("settlementUser","enum.workOrderV2NodeLogInfo.attrName.settlementUser", "settlementUser", FieldTypeEnum.USER.getType(),
            1, 0, 0, ShowTypeEnum.ALL.getCode(), 13, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    ;

    /**
     * 英文名称
     */
    private String attr;
    /**
     * 中文名称
     */
    private String attrName;
    /**
     * 对应saas中的attr
     */
    private String saasAttr;
    /**
     * 字段类型，详见
     *
     * @see FieldTypeEnum
     */
    private Integer fieldType;
    /**
     * 重命名、判重、启用必填等权限
     * 1.重命名+字段权限
     * 2.重命名+字段权限+查重
     * 3.重命名+字段权限+启用、必填
     * 4.重命名+字段权限+查重+启用、必填
     * 注：pro中启用和必填是同一个权限，同时启用或同时关闭
     */
    private Integer setType;
    /**
     * 模板设计阶段字段是否允许编辑
     * 1：允许编辑
     * 0：不允许编辑
     */
    private Integer designEditable;
    /**
     * 字段是否显示在模板设计界面
     * 1：不显示
     * 0：显示
     */
    private Integer editHide;
    /**
     * 字段在各个界面（新建、编辑、列表、详情）的展现形式
     * *0：全部都显示
     * *1：新建编辑显示
     * *2：列表显示
     * *3：详情显示
     * *4：新建编辑、列表显示
     * *5：新建编辑、详情显示
     * *6：列表、详情显示
     * *7:都不显示
     * *8:仅新建不展示
     * *9:导出可见导入不可见
     * *...
     *
     * @see ShowTypeEnum
     */
    private Integer showType;
    /**
     * 字段在模板设计界面的排序
     * 建议不要用连续的数字，可以用等差数列，以防以后在两个字段之间加入新字段
     */
    private Integer sort;
    /**
     * 字段在各个界面是否可见(启用)
     * 1：可见
     * 0：不可见
     * 注：字段在具体页面的可见性需要用属性和showType联合判断，在visible=1的情况下判断showType
     */
    private Integer visible;
    /**
     * 字段是否必填
     * 1：必填
     * 0：不必填
     */
    private Integer required;
    /**
     * 筛选类型
     * 0:不可操作字段标识
     * 1:展示字段标识 (只限于展示 不可分组 查询)
     * 2:查询字段字段标识 (只限于查询展示 不可分组)
     * 3:分组/分类/系列字段标识 (可查询 分组 展示)
     * 4:关联字段标识
     */
    private Integer screenType;

    /**
     * 构造方法
     * @param attr attr
     * @param attrName attrName
     * @param saasAttr saasAttr
     * @param fieldType fieldType
     * @param setType setType
     * @param designEditable designEditable
     * @param editHide editHide
     * @param showType showType
     * @param sort sort
     * @param visible visible
     * @param required required
     * @param screenType screenType
     */
    WorkOrderV2NodeLogInfoEnum(String attr, String attrName, String saasAttr, Integer fieldType, Integer setType, Integer designEditable,
                               Integer editHide, Integer showType, Integer sort, Integer visible, Integer required, Integer screenType) {
        this.attr = attr;
        this.attrName = attrName;
        this.saasAttr = saasAttr;
        this.fieldType = fieldType;
        this.setType = setType;
        this.designEditable = designEditable;
        this.editHide = editHide;
        this.showType = showType;
        this.sort = sort;
        this.visible = visible;
        this.required = required;
        this.screenType = screenType;
    }

    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }

    /**
     * 获取所有属性值
     *
     * @return
     */
    public static List<String> getAllAttr(){
        return Arrays.stream(WorkOrderV2NodeLogInfoEnum.values()).map(WorkOrderV2NodeLogInfoEnum::getAttr).collect(Collectors.toList());
    }

    /**
     * 按字段类型获取属性
     *
     * @param fieldType
     * @return
     */
    public static List<String> getAttrByFieldType(Integer fieldType){
        return Arrays.stream(WorkOrderV2NodeLogInfoEnum.values())
                .filter(workOrderV2NodeLogInfoEnum -> Objects.equals(workOrderV2NodeLogInfoEnum.getFieldType(), fieldType))
                .map(WorkOrderV2NodeLogInfoEnum::getAttr).collect(Collectors.toList());
    }
}
